package com.cyz.user.userService.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyz.common.bean.Path;
import com.cyz.common.mapper.PathMapper;
import com.cyz.user.userService.PathCardService;
import com.cyz.user.userService.PathService;
import com.cyz.common.utils.BeanCopyUtil;
import com.cyz.common.utils.R;
import com.cyz.user.vo.PathVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 34928
* @description 针对表【path】的数据库操作Service实现
* @createDate 2023-02-22 15:09:34
*/
@Service
public class PathServiceImpl extends ServiceImpl<PathMapper, Path>
    implements PathService {

    @Autowired
    private PathCardService pathCardService;

    @Override
    public R queryAllPath() {
        return null;
    }

    @Override
    public R queryPaths() {
        List<Path> list = list();
//        item.setList(pathMapper.getList(1))
        List<PathVo> pathVos = BeanCopyUtil.copyBeanList(list, PathVo.class);
//        pathVos.stream()
//                .forEach(item -> item.setList(pathMapper.getList(item.getId())));
        return R.success(pathVos);
    }

    @Override
    public R queryPathsAndCards() {
        List<Path> list = list();
        List<PathVo> pathVos = BeanCopyUtil.copyBeanList(list, PathVo.class);
        pathVos.forEach(item -> {
            item.setPathCards(pathCardService.getPathCardsByPathId(item.getId()));
        });
        return R.success(pathVos);
    }
}




